package com.zerowidth.moc.web.controller;


import com.zerowidth.moc.web.auth.annotation.NeedToken;
import com.zerowidth.moc.web.controller.service.BabyService;
import com.zerowidth.moc.web.resp.ResultBean;
import com.zerowidth.db.bean.BabyBean;
import com.zerowidth.db.bean.vm.BabyRelationVM;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1")
public class BabyController {

    @Autowired
    BabyService babyService;

    @NeedToken
    @PostMapping("/baby")
    public ResponseEntity<ResultBean<BabyRelationVM>> createBaby(
            @RequestParam("creator_user_id") String creatorUserId,
            @RequestParam("relation") String relation,
            @RequestBody BabyBean babyBean) {

        return babyService.createBaby(creatorUserId, relation, babyBean);
    }

    @NeedToken
    @GetMapping("/babylist")
    public ResponseEntity<ResultBean<List<BabyRelationVM>>> getBabyRelationList(
            @RequestParam("user_id") String user_id) {

        return babyService.getBabyRelationList(user_id);
    }

    @NeedToken
    @PostMapping("/relation")
    public ResponseEntity<ResultBean<BabyRelationVM>> createRelation(
            @RequestParam("user_id") String user_id,
            @RequestParam("invite_code") String invite_code) {

        return babyService.createInviteRelation(user_id, invite_code);
    }

    @NeedToken
    @PostMapping("/baby/top")
    public ResponseEntity<ResultBean<Void>> setBabyTop(
            @RequestParam("baby_id") String babyId) {

        return babyService.setBabyTop(babyId);
    }

    @NeedToken
    @PostMapping("/baby/delete")
    public ResponseEntity<ResultBean<Void>> deleteBaby(
            @RequestParam("baby_id") String babyId) {

        return babyService.deleteBaby(babyId);
    }

    @NeedToken
    @PostMapping("/baby/unfollow")
    public ResponseEntity<ResultBean<Void>> unFollowBaby(
            @RequestParam("baby_id") String babyId) {

        return babyService.unFollowBaby(babyId);
    }

    @NeedToken
    @PostMapping("/baby/modify")
    public ResponseEntity<ResultBean<Void>> modifyBabyInfo(
            @RequestParam("baby_id") String baby_id,
            @RequestParam("avatar") String avatar,
            @RequestParam("nick_name") String nick_name,
            @RequestParam("birthday") String birthday,
            @RequestParam("gender") int gender) {

        return babyService.modifyBabyInfo(baby_id, avatar, nick_name, birthday, gender);
    }

}
